/*************************************************
* Title：TinyToolKit
* Author：Opportunity 
* Describe：绘制音效管理器的窗口
* CreateTime：2020-07-07 16:31:20
* Version：1.0
* Modify Recorder：
*************************************************/

using TinyToolKit;
using TinyToolKit.DataTree;
using UnityEditor;
using UnityEngine;

namespace TinyToolKitEditor
{
    public class DrawWindowDataNode : DrawWindowBase
    {
        private TDataNodeManager _dataNodeManager;

        public override void InitWindow(ScriptableObject setting)
        {
        }

        protected override void DrawInternalMainGUI()
        {
            TinyToolWindowUtil.DrawDefaultEditorGUI();
            
            if (EditorApplication.isPlaying == false || TinyTool.Instance.HasManager<TDataNodeManager>() == false) return;
            if (_dataNodeManager == null) _dataNodeManager = TinyTool.Instance.GetManager<TDataNodeManager>();
            
            if (_dataNodeManager.Root != null)
                DrawDataNode(_dataNodeManager.Root);
        }
        
        private void DrawDataNode(DataNode dataNode)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.TextField(dataNode.FullName,EditorStyles.label);
            EditorGUILayout.LabelField(dataNode.ToDataString());
            EditorGUILayout.EndHorizontal();
            
            DataNode[] children = dataNode.GetAllChildNodes();

            if (children != null && children.Length > 0)
            {
                foreach (DataNode node in children)
                {
                    DrawDataNode(node);
                }
            }
        }
    }
}